package net.randomice.emf.observables.demo.extlibrary.observables;

import net.randomice.emf.observables.demo.extlibrary.ExtlibraryFactory;
import net.randomice.emf.observables.demo.extlibrary.ExtlibraryPackage;
import net.randomice.emf.observables.demo.extlibrary.Library;
import net.randomice.emf.observables.demo.extlibrary.items.Book;
import net.randomice.emf.observables.demo.extlibrary.items.Item;
import net.randomice.emf.observables.demo.extlibrary.items.observables.BookOL;
import net.randomice.emf.observables.demo.extlibrary.items.observables.ItemOL;
import net.randomice.emf.observables.demo.extlibrary.persons.Person;
import net.randomice.emf.observables.demo.extlibrary.persons.Writer;
import net.randomice.emf.observables.demo.extlibrary.persons.observables.PersonOL;
import net.randomice.emf.observables.demo.extlibrary.persons.observables.WriterOL;
import net.randomice.emf.observables.runtime.IObservableAbstractListObject;
import net.randomice.emf.observables.runtime.IObservableObject;
import org.eclipse.core.databinding.observable.Observables;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * An Observable object wrapper for {@link Library}
 * @generated
 */
public class LibraryOO implements IObservableObject<Library> {
	// root object stuff

	public final static Creator<Library, LibraryOO> CREATOR = new Creator<Library, LibraryOO>() {
		public LibraryOO createRoot(Library object) {
			return new LibraryOO(Observables.constantObservableValue(object,
					Library.class));
		}

		public LibraryOO createRoot() {
			return createRoot(ExtlibraryFactory.eINSTANCE.createLibrary());
		}
	};

	public static LibraryOO createRoot(Library object) {
		return CREATOR.createRoot(object);
	}

	public static LibraryOO createRoot() {
		return CREATOR.createRoot();
	}

	// instance stuff	

	public final IObservableValue o;
	public final IObservableValue getObservable() {
		return o;
	}

	public LibraryOO(IObservableValue observableValue) {
		Object type = observableValue.getValueType();
		if (type instanceof EReference) {
			type = ((EReference) type).getEType().getInstanceClass();
		}
		Assert.isTrue(null == type || Library.class.equals(type));
		o = observableValue;
	}

	public Library getValue() {
		return (Library) o.getValue();
	}

	public void setValue(Library newValue) {
		o.setValue(newValue);
	}

	// generic feature getters

	public IObservableValue getValueFeature(EStructuralFeature feature) {
		if (ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS.equals(feature)) {
			return getAddress();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__NAME.equals(feature)) {
			return getName();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__PARENT_BRANCH.equals(feature)) {
			return getParentBranch().o;
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableList getListFeature(EStructuralFeature feature) {
		if (ExtlibraryPackage.Literals.LIBRARY__WRITERS.equals(feature)) {
			return getWriters().o;
		}
		if (ExtlibraryPackage.Literals.LIBRARY__STOCK.equals(feature)) {
			return getStock().o;
		}
		if (ExtlibraryPackage.Literals.LIBRARY__BOOKS.equals(feature)) {
			return getBooks().o;
		}
		if (ExtlibraryPackage.Literals.LIBRARY__BRANCHES.equals(feature)) {
			return getBranches().o;
		}
		if (ExtlibraryPackage.Literals.LIBRARY__CASTS.equals(feature)) {
			return getCasts().o;
		}
		if (ExtlibraryPackage.Literals.LIBRARY__READERS.equals(feature)) {
			return getReaders().o;
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableObject<?> getValueObject(EReference feature) {
		if (ExtlibraryPackage.Literals.LIBRARY__PARENT_BRANCH.equals(feature)) {
			return getParentBranch();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableAbstractListObject<?> getListObject(EReference feature) {
		if (ExtlibraryPackage.Literals.LIBRARY__WRITERS.equals(feature)) {
			return getWriters();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__STOCK.equals(feature)) {
			return getStock();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__BOOKS.equals(feature)) {
			return getBooks();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__BRANCHES.equals(feature)) {
			return getBranches();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__CASTS.equals(feature)) {
			return getCasts();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__READERS.equals(feature)) {
			return getReaders();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	// features from type Addressable

	private IObservableValue address = null;
	public IObservableValue getAddress() {
		if (null == address) {
			address = EMFObservables.observeDetailValue(o.getRealm(), o,
					ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS);
		}
		return address;
	}

	public void setAddress(String value) {
		getAddress().setValue(value);
	}

	// features from type Library

	private IObservableValue name = null;
	public IObservableValue getName() {
		if (null == name) {
			name = EMFObservables.observeDetailValue(o.getRealm(), o,
					ExtlibraryPackage.Literals.LIBRARY__NAME);
		}
		return name;
	}

	public void setName(String value) {
		getName().setValue(value);
	}

	private WriterOL writers = null;
	public WriterOL getWriters() {
		if (null == writers) {
			writers = new WriterOL(EMFObservables
					.observeDetailList(o.getRealm(), o,
							ExtlibraryPackage.Literals.LIBRARY__WRITERS));
		}
		return writers;
	}

	private ItemOL stock = null;
	public ItemOL getStock() {
		if (null == stock) {
			stock = new ItemOL(EMFObservables.observeDetailList(o.getRealm(),
					o, ExtlibraryPackage.Literals.LIBRARY__STOCK));
		}
		return stock;
	}

	private BookOL books = null;
	public BookOL getBooks() {
		if (null == books) {
			books = new BookOL(EMFObservables.observeDetailList(o.getRealm(),
					o, ExtlibraryPackage.Literals.LIBRARY__BOOKS));
		}
		return books;
	}

	private LibraryOL branches = null;
	public LibraryOL getBranches() {
		if (null == branches) {
			branches = new LibraryOL(EMFObservables.observeDetailList(o
					.getRealm(), o,
					ExtlibraryPackage.Literals.LIBRARY__BRANCHES));
		}
		return branches;
	}

	private LibraryOO parentBranch = null;
	public LibraryOO getParentBranch() {
		if (null == parentBranch) {
			parentBranch = new LibraryOO(EMFObservables.observeDetailValue(o
					.getRealm(), o,
					ExtlibraryPackage.Literals.LIBRARY__PARENT_BRANCH));
		}
		return parentBranch;
	}

	public void setParentBranch(Library value) {
		getParentBranch().setValue(value);
	}

	private PersonOL casts = null;
	public PersonOL getCasts() {
		if (null == casts) {
			casts = new PersonOL(EMFObservables.observeDetailList(o.getRealm(),
					o, ExtlibraryPackage.Literals.LIBRARY__CASTS));
		}
		return casts;
	}

	private PersonOL readers = null;
	public PersonOL getReaders() {
		if (null == readers) {
			readers = new PersonOL(EMFObservables
					.observeDetailList(o.getRealm(), o,
							ExtlibraryPackage.Literals.LIBRARY__READERS));
		}
		return readers;
	}

}
